#include <stdio.h>
#include <string.h>
#include <errno.h>

int mycpy(FILE *rfp, FILE *wfp);

int main(int argc, char **argv)
{
	FILE *fp1, *fp2;

	if (argc < 3)
		return 1;

	fp1 = fopen(argv[1], "r");
	if (NULL == fp1) {
		fprintf(stderr, "fopen %s failed: %s\n", argv[1], strerror(errno));
		return 1;
	}
	fp2 = fopen(argv[2], "w");
	if (NULL == fp2) {
		fclose(fp1);
		fprintf(stderr, "fopen %s failed: %s\n", argv[2], strerror(errno));
		return 1;
	}

	mycpy(fp1, fp2);

	fclose(fp1);
	fclose(fp2);

	return 0;
}

int mycpy(FILE *rfp, FILE *wfp)
{
	int c;

	while (1) {
		c = fgetc(rfp);
		if (EOF == c) break;
		fputc(c, wfp);
	}

	return 0;
}

